#include <stdio.h>
#include <errno.h>
#include <string.h>
typedef struct str
{
    char name[128];
    int id;
    char ch;
}str;


#define FOPEN_ERR(FP) if (NULL == FP) \
    { \
    perror("fopen error:"); \
    return 0; \
    } \


int main(int argc, char const *argv[])
{
    str s_srr[5] = {
        {"张1",1,'\n'},
        {"张2",2,'\n'},
        {"张3",3,'\n'},
        {"张4",4,'\n'},
        {"张5",5,'\n'},
    };
    str s_srr_1[5] = {};
    //清空结构体
    memset(s_srr_1, 0 ,sizeof(s_srr_1));
    //打开文件
    FILE *fp = fopen("张三.txt","w+");
    FOPEN_ERR(fp);
    //向程序中写入
    fseek(fp , 0 , SEEK_SET);//从头开始
    fwrite(s_srr , sizeof(str) , sizeof(s_srr)/sizeof(str),fp);

    fseek(fp , 0 ,SEEK_SET);//从头开始
    fread(s_srr_1 , sizeof(str) , sizeof(s_srr)/sizeof(str),fp);
    for (size_t i = 0; i < 5; i++)
    {
        printf("%s%d%c",s_srr_1[i].name,s_srr_1[i].id,s_srr_1[i].ch);
    }
    
    fclose(fp);
    
    return 0;
}
